﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Golden_Miner
{
    public partial class FrmMain : Form
    {
        private Game game;

        public FrmMain()
        {
            InitializeComponent();
        }

        private void FrmMain_Load(object sender, EventArgs e)
        {           
        }
        private void button1_Click(object sender, EventArgs e)
        {
            game = new Game();
            game.gameChanged += Game_gameChanged;
            game.gameWin += Game_gameWin;
            game.gameLose += Game_gameLose;
            this.gameAera.Invalidate();
            button1.Visible = false;
        }
        private void gameAera_Paint(object sender, PaintEventArgs e)
        {
            if (game != null)
            {
                game.Draw(e.Graphics, this.gameAera.Size);
            }
        }

        private void gameAera_Load(object sender, EventArgs e)
        {
            
        }

        private void Game_gameChanged()
        {
            if (game != null)
            {
                gameAera .Invalidate();
            }
        }

        private void Game_gameWin()
        {
            gameAera.Invalidate();
        }

        private void Game_gameLose()
        {
            gameAera.Invalidate();          
        }

        private void FrmMain_KeyDown(object sender, KeyEventArgs e)
        {
            if(game !=null)
            {
                game.KeyDown(e.KeyCode);
            }
        }

    }
}
